const app = require('./app');
const port = process.env.PORT || 3000;
const os = require('os');

const currentIP = getCurrentIP();

app.listen(port, () => {
  console.error('本机IP访问地址:', `http://${currentIP}:${port}`);
  console.error(`localhost访问地址: http://localhost:${port}`);
  console.error(`本地访问地址: http://127.0.0.1:${port}`);
});

// 获取本机IP地址
function getCurrentIP() {
  const interfaces = os.networkInterfaces();
  for (const iface in interfaces) {
    for (const alias of interfaces[iface]) {
      if (alias.family === 'IPv4' && !alias.internal) {
        return alias.address;
      }
    }
  }
  return '0.0.0.0'; // 如果没有找到合适的IP，则返回一个默认值
}